import java.util.Arrays;

public class MyStack {
    public int[] arr;
    public int size;
    public MyStack() {
        this.arr = new int[10];
    }
    private void ensureCapacity(){
        if(size==arr.length)
        {
            arr= Arrays.copyOf(arr,size*2);
        }
    }
    public int push(int x){
        ensureCapacity();
        arr[size++]=x;
        return x;
    }
    public boolean empty(){
        return 0 == size;
    }
    public int pop() {
        if(empty()) {
            throw new EmptyException("栈是空的！");
        }
        return arr[--size];
    }
    public int size(){
        return size;
    }
    public int peek(){
        if(empty()) {
            throw new EmptyException("栈是空的！");
        }
        return arr[size-1];
    }
}
